package com.wangsh.usersCenter.web.back.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.wangsh.usersCenter.common.controller.BaseController;
import com.wangsh.usersCenter.common.pojo.ApiResponse;
import com.wangsh.usersCenter.common.util.ConstatFinalUtil;
import com.wangsh.usersCenter.common.util.DateFormatUtil;
import com.wangsh.usersCenter.common.util.PageInfoUtil;
import com.wangsh.usersCenter.common.util.RedisUtil;
import com.wangsh.usersCenter.users.pojo.AUsers;
import com.wangsh.usersCenter.users.service.IRbacDbService;
import com.wangsh.usersCenter.users.service.IUsersDbService;


/**
 * 	管理员首页操作
 * 	@author wangsh
 */
@Controller
@RequestMapping("/back/users/")
public class UsersBackController extends BaseController
{
	@Resource
	private IUsersDbService usersDbService;
	@Resource
	private RedisUtil redisUtil;
	@Resource
	private DateFormatUtil dateFormatUtil;
	@Resource
	private IRbacDbService rbacDbService;
	
	/**
	 * 用户列表
	 * @return
	 */
	@RequestMapping("/usersList")
	public String usersList(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--usersList--");
		/* 分页信息 */
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		/* 搜索条件,生成公共的搜索条件 */
		Map<String, Object> condMap = this.proccedSearch(request);
		/* 查询数据库
		 * 所有的数据以JSON的形式返回
		 *  */
		ApiResponse<AUsers> response = this.usersDbService.findCondListUsersService(pageInfoUtil, condMap);
		/* 将结果存储到Request中 */
		model.addAttribute("response", response.toJSON());
		return "/back/users/usersList";
	}
	
	/**
	 * 用户查看
	 * @return
	 */
	@RequestMapping("/usersInfo")
	public String usersUpdate(String id,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--usersInfo--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<AUsers> response = this.usersDbService.findOneUsersService(condMap);
		/* 存储request */
		model.addAttribute("response", response.toJSON());
		return "/back/users/usersInfo";
	}
}